package com.sky.mapper;

import com.sky.entity.AddressBook;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author iTaotao
 * @version 1.0
 * @Description
 * @createTime 2023年08月03日 09:40:00
 */
@Mapper
public interface AddressBookMapper {
    /**
     * 地址列表
     *
     * @return {@link List}<{@link AddressBook}>
     */
    List<AddressBook> list();

    /**
     * 插入地址
     *
     * @param addressBook 地址本
     */
    void insertAddressBook(AddressBook addressBook);

    /**
     * 更新默认地址
     *
     * @param addressBook 地址本
     */
    void updateDefault(AddressBook addressBook);

    /**
     * 查询默认地址
     *
     * @return {@link List}<{@link AddressBook}>
     */
    @Select("select * from address_book where user_id = #{userId} and is_default = #{isDefault}")
    List<AddressBook> selectDefaultAddressBook(AddressBook addressBook);

    /**
     * 更新地址通过id
     *
     * @param addressBook 地址本
     */
    void updateAddressBookById(AddressBook addressBook);


    /**
     * 选择地址通过id
     *
     * @param id     id
     *
     * @return {@link AddressBook}
     */
    AddressBook selectAddressById(Long id);

    /**
     * 删除地址通过id
     *
     * @param addressBook 地址本
     */
    @Delete("delete from address_book where user_id = #{userId} and id = #{id}")
    void deleteAddressById(AddressBook addressBook);
}
